package com.obas.business.analogy.service.impl;

import java.util.Date;

import com.ease.common.vo.MapParameter;
import com.obas.business.analogy.service.KpiStandardAnalogyProcessService;
import com.obas.business.analogy.util.AnalogyTableNameUtil;
import com.obas.business.analogy.vo.AnalogyContextParam;
import com.obas.model.type.AnalogyValueAttributeType;

public class KpiStandardAnalogyProcessServiceImpl extends AbstractAnalogyProcessServiceImpl<AnalogyContextParam> implements KpiStandardAnalogyProcessService {

	static class Operation {
		static String insertSummation = "insertSummation";
		static String updateSummation = "updateSummation";
		static String aggregate = "aggregate";
		static String accumulateAggregate = "accumulateAggregate";
	}

	public void process(AnalogyContextParam analogyContextParam) {

//		analogyContextParam.setProcessDimensionType(ProcessDimensionType.KPI_STANDARD);

		String tableName = AnalogyTableNameUtil.tableName(analogyContextParam);
		Date batchTimestamp = analogyContextParam.getBatchTimestamp();

		MapParameter parameter = new MapParameter();
		parameter.put("tableName", tableName);
		parameter.put("sequenceName", AnalogyTableNameUtil.sequenceName(tableName));

		String sourceTableName =null;// AnalogyTableNameUtil.tableName(analogyContextParam.getAnalogyDimensionType(), analogyContextParam.getTimeDimensionType(), ProcessDimensionType.RAW);
		parameter.put("sourceTableName", sourceTableName);
		parameter.put(AnalogyValueAttributeType.BATCHTIMESTAMP.getName(), batchTimestamp);

		this.getJdbcTemplateDataAccessObject().execute(statement(Operation.insertSummation, parameter), parameter);

		this.getJdbcTemplateDataAccessObject().update(statement(Operation.updateSummation, parameter), parameter);

		this.getJdbcTemplateDataAccessObject().update(statement(Operation.aggregate, parameter), parameter);

		this.getJdbcTemplateDataAccessObject().update(statement(Operation.accumulateAggregate, parameter), parameter);

	}

}
